﻿using AutoMapper;

namespace DDDNorthWind.Core.Domain.ValueObject
{
    public abstract class ValueObject<T> : IValueObject<T> where T : class, new()
    {
        private static readonly T NullValueObject = new T();

        /// <summary>
        /// Determines whether [is null or empty] [the specified value object].
        /// </summary>
        /// <param name="valueObject">The value object.</param>
        /// <returns>
        /// 	<c>true</c> if [is null or empty] [the specified value object]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsNullOrEmpty(T valueObject)
        {
            return (valueObject == null || valueObject.Equals(NullValueObject));
        }

        /// <summary>
        /// Equalses the specified obj.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        public abstract bool Equals(T obj);

        /// <summary>
        /// Updates the values.
        /// </summary>
        /// <param name="other">The other.</param>
        public virtual void UpdateValues(T other)
        {
            Mapper.Map(other, this as T);
        }

        /// <summary>
        /// Gets the empty.
        /// </summary>
        /// <value>The empty.</value>
        public static T Empty
        {
            get { return new T(); }
        }
    }
}